package org.scs.carleton.ca.pgdt.core.internal.parser;

import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTNode;
import org.scs.carleton.ca.pgdt.core.parser.nodes.IASTTranslationUnit;

/**
 * The physical implementation for an ASTNode.  External use of this class is inadvisable.
 * 
 * @author tessierj
 *
 */
public abstract class ASTNode implements IASTNode {
	private ASTTranslationUnit translationUnit;
	private ASTNode owner;
	private int type, startOffset, endOffset;
	
	public ASTNode(ASTTranslationUnit translationUnit, int type) {
		this.translationUnit = translationUnit;
		this.type = type;
	}

	@Override
	public IASTNode getOwner() {
		return owner;
	}
	
	public IASTTranslationUnit getTranslationUnit() {
		return translationUnit;
	}
	
	public int getType() {
		return type;
	}
	
	public void setOwner(ASTNode node) {
		this.owner = node;
	}

	@Override
	public int getEndOffset() {
		return endOffset;
	}

	@Override
	public int getLength() {
		return endOffset - startOffset;
	}

	@Override
	public int getStartOffset() {
		return startOffset;
	}
	
	public void setStartLocation(ASTLocation location) {
		startOffset = translationUnit.getOffset(location.getBeginColumn(), location.getBeginLine());
	}
	
	public void setEndLocation(ASTLocation location) {
		endOffset = translationUnit.getOffset(location.getEndColumn(), location.getEndLine());
	}
}
